﻿import QtQuick 2.0

Rectangle {
    width: 240
    height: 120

    Text {
        id: label
        x: 24
        y: 24
        property int spacePresses: 0
        text: 'Space pressed: ' + spacePresses + ' times'

        // handler for text changes
        onTextChanged: console.log('text changed to:', text)

        focus: true

        //(2) handler with some JS
        Keys.onSpacePressed: {
            increment()
        }

        Keys.onEscapePressed: {
            //     label.text = ''
            spacePresses = 0
        }

        function increment() {
            spacePresses = spacePresses + 1
        }
    }
}
